#include <JXQCore/JThread>
#include <JXQCore/JDebug>
#include <JXQIO/JIONotifier>

#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace JXQ;

int main(int argc, char *argv[])
{
	J_UNUSED(argc);
	J_UNUSED(argv);

	int fd[3] = {};
	fd[0] = open("/dev/input/mouse0", O_RDONLY);
	fd[1] = open("/dev/input/mouse1", O_RDONLY);
	fd[2] = open("/dev/input/mouse2", O_RDONLY);

	JMultiIONotifier jiomp;
	jiomp.registerDescriptor(new JIONotifier(fd[0]));
	jiomp.registerDescriptor(new JIONotifier(fd[1]));
	jiomp.registerDescriptor(new JIONotifier(fd[2]));

	jiomp.ready.subscribe([](int fd, JIONotifier::Type type)
	{
		uint8_t buf[3] = {};
		read(fd, buf, sizeof(buf));
		jDebug() << type << "---" << buf[0] << buf[1] << buf[2];
	});

	JThread::sleep(300);

	return 0;
}
